﻿using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.Generic;
using InformationSystem.Framework.Dao.Dialect;
using System.Data;

namespace InformationSystem.Framework.Dao
{
    public class InfoSysAdoDaoSupport : AdoDaoSupport
    {
        public new MSSQLAdoTemplate AdoTemplate
        {
            get { return base.AdoTemplate as MSSQLAdoTemplate; }
            set { base.AdoTemplate = value; }
        }

        protected int GetUseableID(string tableName, string columnName)
        {
            string selectSql = string.Format("select case when max({0}) is null then 1 else max({0})+1 end as nextid from {1}", columnName, tableName);
            return (int)AdoTemplate.ExecuteScalar(CommandType.Text, selectSql);
        }

        protected int GetUseableID(string tableName, string columnName, string wherefilter)
        {
            string selectSql = string.Format("select case when max({0}) is null then 1 else max({0})+1 end as nextid from {1} where {2}", columnName, tableName, wherefilter);
            return (int)AdoTemplate.ExecuteScalar(CommandType.Text, selectSql);
        }
    }
}
